package com.winiex.weibospider;

import weibo4j.http.AccessToken;
import weibo4j.http.HttpClient;
import weibo4j.http.PostParameter;
import weibo4j.http.RequestToken;
import weibo4j.http.Response;

public class OAuth {
	private final String BASE_URL = "http://api.t.sina.com.cn/";
	
	private String consumerKey = "740792781";
	private String consumerSecret = "0061a70fe53ba63b265aca46a814220e";
	
	public static String accessToken = "ade9d24aef180a37a5081d83e99371b3";
	public static String accessTokenSecret = "2ce9799c3069cbaf3aee957c97437422";
	private HttpClient client = new HttpClient();
	
	public RequestToken request(String backUrl) {
		try {
			client.setOAuthConsumer(consumerKey, consumerSecret);
			
			RequestToken requestToken = client.getOauthRequestToken(backUrl);

			System.out.println("Got request token.");
			System.out.println("Request token: " + requestToken.getToken());
			System.out.println("Request token secret: "
					+ requestToken.getTokenSecret());
			return requestToken;
		} catch (Exception e) {
			e.printStackTrace();
			return null;
		}
	}

	public AccessToken requstAccessToken(RequestToken requestToken,
			String verifier) {
		try {
			
			AccessToken accessToken = client.getOAuthAccessToken(requestToken
					.getToken(), requestToken.getTokenSecret(), verifier);

			System.out.println("Got access token.");
			System.out.println("access token: " + accessToken.getToken());
			System.out.println("access token secret: "
					+ accessToken.getTokenSecret());
			return accessToken;
		} catch (Exception e) {
			e.printStackTrace();
			return null;
		}
	}
	
	public void update(String content) {
		client.setToken(accessToken, accessTokenSecret);
		try {
			
		} catch (Exception e) {
		}
		
		
	}
}
